﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1
{
    public class Operand
    {
        #region Constructed Function
        public Operand(OperandType type, object value)
        {
            this.Type = type;
            this.Value = value;
        }

        public Operand(string opd, object value)
        {
            this.Type = ConvertOperand(opd);
            this.Value = value;
        }
        #endregion

        #region Variable &　Property

        public OperandType Type { get; set; }

        public string Key { get; set; }

        public object Value { get; set; }

        #endregion

        #region Public Method

        public static OperandType ConvertOperand(string opd)
        {
            if (opd.IndexOf("(") > -1)
            {
                return OperandType.FUNC;
            }
            else if (IsNumber(opd))
            {
                return OperandType.NUMBER;
            }
            else if (IsDate(opd))
            {
                return OperandType.DATE;
            }
            else
            {
                return OperandType.STRING;
            }
        }

        public static bool IsNumber(object value)
        {
            double val;
            return double.TryParse(value.ToString(), out val);
        }

        public static bool IsDate(object value)
        {
            DateTime dt;
            return DateTime.TryParse(value.ToString(), out dt);
        }

        #endregion
    }
}
